package com.bbs.dao.impl;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.bbs.dao.BaseDao;
import com.bbs.model.Section;
import com.bbs.model.Topic;

public class IndexDaoImpl extends BaseDao{
	public static void main(String[] args) throws IOException {
		/*IndexDaoImpl impl=new IndexDaoImpl();
		Map<Section, List<Topic>> rMap=new HashMap<Section, List<Topic>>();
		impl.assembContent(rMap);
		Set<Section> sections= rMap.keySet();
		for(Section section:sections){
		  System.out.println(rMap.get(section));
		}*/
		
	}
	public IndexDaoImpl() throws IOException {
		super();
		// TODO Auto-generated constructor stub
	}
	//old version 
	/*public void assembContent(Map<Section, List<Topic>> rMap) throws IOException{
		List<Section> sections=sqlSession.selectList("com.bbs.model.Section.listSection");
		for(Section section :sections){
			List<Topic> topics=sqlSession.selectList("com.bbs.model.Index.findTopicsBySectionId",section.getSection_id());
			rMap.put(section, topics);
		}
		sqlSession.commit();
		sqlSession.close();
	}*/
	//updated version 2013-5-30 10:40:03
	public void assembContent(Map<Section, List<Topic>> rMap) throws IOException{
		List<Section> sections=sqlSession.selectList("com.bbs.model.Section.listSection");
		for(Section section :sections){
			List<Topic> topics=sqlSession.selectList("com.bbs.model.Index.indexFindTopicsBySectionId",section.getSection_id());
			rMap.put(section, topics);
		}
		sqlSession.commit();
		sqlSession.close();
	}
	
}
